package com.course.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * @author bigFish
 * @Title: public:
 * 数据库操作对象
 */
public class DatabaseUtil {
    public static SqlSession getSqlSession() throws IOException {
        //获取资源配置文件
        Reader database = Resources.getResourceAsReader("databaseConfig.xml");

        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(database);

        //执行配置文件中的SQL语句
        SqlSession sqlSession = build.openSession();

        return sqlSession;
    }
}
